package Model.Gates;

import Model.Main.Wire;
import java.util.ArrayList;
import java.util.logging.*;

/**
 * 
 * @author citromos pufóka
 */
public class Oscilloscope extends Gate {

    private ArrayList<Boolean> memory;

    public Oscilloscope(String name) {
        this.name = name;
        maxInputs = 1;
        this.reset();
        memory = new ArrayList<Boolean>();
        for (int i = 0; i <= 15; i++) {
            memory.add(Boolean.FALSE);
        }
        logger.log(Level.FINE, "" + this.getClass().getName() + " " + this.getName() + " created with " + maxInputs + " input(s).");
        /**
         * Inicializáljuk az inputsWired listát.
         */
        initInputsWired();
    }

    @Override
    public void setInput(int inputNumber, Boolean val) {
        logger.log(Level.CONFIG, "" + this.getClass().getName() + " " + this.getName() + " got value and shifting.");
        for (int i = 15; i >0; i--) {
            memory.set(i, memory.get(i-1));
        }
        logger.log(Level.CONFIG, "" + this.getClass().getName() + " " + this.getName() + " adding value " + val + " to place 0 on memory.");
        this.val = val;
        memory.set(0, val);
    }

    @Override
    public Boolean getVal() {
        return (memory.get(0));
    }
    
    /**
     * Memorát adát
     * @return 
     */
    public ArrayList<Boolean> getMemory(){
        return memory;
    }
    
    /**
     * Ennek nincsen kimenetele.
     * @param w
     * @param inputNumber
     */
    @Override
    public void setOutputWire(Wire w, int inputNumber) {
        throw new UnsupportedOperationException("No outputs for " + this);
    }
}
